package com.zqt.zqt805.controller;

import com.zqt.zqt805.domain.Category;
import com.zqt.zqt805.service.CategoryService;
import com.zqt.zqt805.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "分类管理接口---张淇童0805")
@RestController
@RequestMapping("/api/categories")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @ApiOperation(value = "查看所有分类", notes = "查看所有产品分类")
    @GetMapping
    public AjaxResult getAllCategories() {
        return AjaxResult.success(categoryService.getAllCategories());
    }

    @ApiOperation(value = "新增分类", notes = "新增一个产品分类")
    @PostMapping
    public AjaxResult addCategory(@RequestBody Category category) {
        categoryService.addCategory(category);
        return AjaxResult.success("Category added successfully", category.getCategory_id());
    }
}